<html>
<head>
    <meta charset="UTF-8">
    <title>socket test</title>
    <!--<script src="./jquery.min.js" type="text/javascript"></script>-->
    <!--<script type="text/javascript" src="./socket.io.js"></script>-->
    <script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/socket.io/2.1.0/socket.io.js"></script>
</head>
<body>
<h1>Netty-socketio demo</h1>
<br />
<div id="console" class="well"></div>
<form class="well form-inline" onsubmit="return false;">
    <input id="to" class="input-xlarge" type="text" placeholder="to. . . " />
    <input id="content" class="input-xlarge" type="text" placeholder="content. . . " />
    <button type="button" onClick="sendMessage()" class="btn">Send</button>
    <button type="button" onClick="sendDisconnect()" class="btn">Disconnect</button>
</form>
<script type="text/javascript">
    var userId =  Math.floor((Math.random()*1000)+1);
    var socket = io.connect('http://10.0.3.6:8089?userId='+userId);
    socket.on('connect',function() {
        //alert("user connect");
        console.log("user connect");
    });

    socket.on('newAlert', function(data) {
        //alert("receive alert");
        console.log("receive message:" + data.message);
    });

    socket.on('disconnect',function() {
        //alert("user disconnect");
        console.log("user disconnect");
    });

    function sendDisconnect() {
        socket.disconnect();
    }

    function sendMessage() {
        console.log("send message:"+$('#content').val());
        socket.emit('token', {
            to : $('#to').val(),
            message : $('#content').val()
        });
    }

</script>
</body>
</html>